<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;
use phpDocumentor\Reflection\Types\Integer;

use Illuminate\Support\Facades\Hash;

class ModifyPasswordRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
        //return Auth::guard('web')->check()
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'old_password' => 'sometimes|required|min:6',     //旧密码
            'new_password' => 'sometimes|required|between:6,15|confirmed',    //新密码
            'new_password_confirmation' => 'sometimes|required'
        ];
    }

    public function messages()
    {

        return [
            'old_password.required' => '原始密码不能为空',
            'old_password.min' => '原始密码不能少于6个字符',
            'new_password.required' => '新始密码不能为空',
            'new_password.between' => '新密码不必须在6~15个字符之间',
            'new_password.confirmed' => '两次输入新密不符',
            'new_password_confirmation.required'=>'确认密码不能为空'
        ];
    }

    protected function failedValidation(Validator $validator)
    {
        throw(new HttpResponseException(response()->json(['massages' => $validator->errors()->all(), 'code' => '100'])));
        //return Hash::check($value, Auth::guard('web')->user()->password);
    }
}